﻿Imports Microsoft.SharePoint
Imports Bussines.logic
Imports System.Data
Partial Class AcuerdosSistemaPoderosa
    Inherits System.Web.UI.Page
    Dim Util As New utiles
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim variosBL As New variosBL
        Dim _Procedure As String = Util.retornarParametros("SPacuerdosPoderosa")
        ViewState("columGrid") = Util.retornarParametros("CampoAcuerdoPoderosa")
        Dim _Campos() As String = ViewState("columGrid").ToString.Split(";")
        Dim Site As SPSite = New SPSite(ConfigurationManager.AppSettings("siteACTAS"))
        Dim web As SPWeb = Site.OpenWeb()
        Dim _user As String = Util.SepararCuentaActiveDirectory(web.CurrentUser.LoginName.ToString())
        _Procedure = _Procedure.Replace("[%usuario%]", _user)
        _Procedure = _Procedure.Replace("--", "").Replace("exec", "").Replace("drop", "").Replace("insert", "")

        Dim dt As New DataTable

        dt = variosBL.ListadoPendientesPoderosa(_Procedure)
        gvListaPendiente.DataSource = dt
        gvListaPendiente.DataBind()
        dt.Dispose()
        web.Close()
        Site.Close()
        For x As Int32 = 0 To gvListaPendiente.Columns.Count - 1
            gvListaPendiente.Columns(x).Visible = False
        Next
        ViewState("columGrid") = _Campos
        For Each item As String In _Campos
            Dim strCampo() As String = item.Split("(")
            Dim strCMP As String = ""
            Dim strDES As String = ""
            If strCampo.Length > 0 Then
                strCMP = strCampo(0)
                strDES = strCampo(1).Replace(")", "")
            End If
            For Each col As DataControlField In gvListaPendiente.Columns
                If col.HeaderText = strCMP.Trim Then
                    col.Visible = True
                    Exit For
                End If
            Next
        Next

    End Sub

    Protected Sub gvListaPendiente_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvListaPendiente.RowCreated
        If (e.Row.RowType = DataControlRowType.Header) Then
            Dim _Campos() As String = ViewState("columGrid").ToString.Split(";")
            For Each item As String In _Campos
                Try
                    Dim strCampo() As String = item.Split("(")
                    Dim strCMP As String = ""
                    Dim strDES As String = ""
                    If strCampo.Length > 0 Then
                        strCMP = strCampo(0)
                        strDES = strCampo(1).Replace(")", "")
                    End If
                    For y As Integer = 0 To e.Row.Cells.Count - 1
                        If e.Row.Cells(y).Text = strCMP.Trim Then
                            e.Row.Cells(y).Text = strDES
                        End If
                    Next
                Catch ex As Exception

                End Try
            Next
        End If
    End Sub
End Class
